from websocket import create_connection
import json
def websocket_client():
    # 连接到 WebSocket 服务器
    ws = create_connection("ws://106.75.148.173:9503/?user_id=12345")  # 替换为实际的 WebSocket 服务器地址
    print("Connected to WebSocket server. You can start sending messages.")
    user_input = input("> ")            
    # 发送消息到服务器
    ws.send(json.dumps({'userid':'12345',"message":user_input}))
    print("发送成功！")
    while True:
        response = ws.recv()
        if(json.loads(response)['message']=='<end>'):
            break
        print(f"{json.loads(response)['message']}",end="", flush=True)
    
# 运行客户端
websocket_client()